package com.daka.service.impl;

import com.daka.dao.VolunteerMapper;
import com.daka.entity.GroupRecruitVolunteer;
import com.daka.entity.Volunteer;
import com.daka.service.VolunteerService;
import com.daka.tools.Page;
import com.daka.vo.request.GroupRecruitVolunteerVo;
import com.daka.vo.request.VolunteerRequestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by yangx
 * Date: 2016/7/25 0025
 * Time: 11:24
 */
@Service("volunteerService")
public class VolunteerServiceImpl implements VolunteerService {

    @Autowired
    private VolunteerMapper volunteerMapper;


    public int insert(Volunteer volunteer){
        return volunteerMapper.insert(volunteer);
    }

    public int update(Volunteer volunteer){
        return volunteerMapper.updateByPrimaryKeySelective(volunteer);
    }

    public Volunteer queryByEntity(Volunteer volunteer){
        return volunteerMapper.selectByStatement(volunteer);
    }

    public Volunteer selectByPrimaryKey(long id){
        return volunteerMapper.selectByPrimaryKey(id);
    }

    public Page<Volunteer> selectByGroupId(VolunteerRequestVo po){
        Page<Volunteer> page =new Page<Volunteer>();
        if(po.getLimitEnd()==0){
            po.setLimitEnd(10);
            po.setLimitStart(10 * po.getLimitStart());
        }else{
            po.setLimitStart(po.getLimitStart() * po.getLimitEnd());
        }
        List<Volunteer> list = volunteerMapper.selectByGroupId(po);
        int count = volunteerMapper.selectByGroupIdCount(po);

        page.setData(list);
        page.setTotalCount(count);

        return page;
    }

    public List<Volunteer> selectByRecruit(GroupRecruitVolunteerVo po){
        return volunteerMapper.selectByRecruit(po);
    }

    public Page<Volunteer> selectByRecruitPage(GroupRecruitVolunteerVo po){
        Page<Volunteer> page =new Page<Volunteer>();
        if(po.getLimitEnd()==0){
            po.setLimitEnd(10);
            po.setLimitStart(10 * po.getLimitStart());
        }else{
            po.setLimitStart(po.getLimitStart() * po.getLimitEnd());
        }
        List<Volunteer> list = volunteerMapper.selectByRecruitPage(po);
        int count = volunteerMapper.selectByRecruitPageCount(po);

        page.setData(list);
        page.setTotalCount(count);

        return page;
    }
    public List<Volunteer> queryByGroupId(VolunteerRequestVo vo){
        return volunteerMapper.queryByGroupId(vo);
    }

    public List<Volunteer> queryManager(long groupId){
        return volunteerMapper.selectManager(groupId);
    }

}
